package com.xqb.modules.controller.study;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.StdInteractionQuestion;
import com.xqb.modules.domain.vo.InteractionQuestionVo;
import com.xqb.modules.service.IStdInteractionQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 互动提问的问题Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/study/interaction_question")
@Slf4j
public class StdInteractionQuestionController extends BaseController
{
    @Autowired
    private IStdInteractionQuestionService stdInteractionQuestionService;

    /**
     * 查询互动提问的问题列表
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:list')")
    @GetMapping("/list")
    public TableDataInfo list(StdInteractionQuestion stdInteractionQuestion, Long insId) {
        startPage();
        startOrderBy();
        List<InteractionQuestionVo> list = stdInteractionQuestionService.getStdInteractionQuestionList(stdInteractionQuestion, insId);
        return getDataTable(list);
    }

    /**
     * 导出互动提问的问题列表
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:export')")
    @Log(title = "互动提问的问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StdInteractionQuestion stdInteractionQuestion)
    {
        List<StdInteractionQuestion> list = stdInteractionQuestionService.selectStdInteractionQuestionList(stdInteractionQuestion);
        ExcelUtil<StdInteractionQuestion> util = new ExcelUtil<StdInteractionQuestion>(StdInteractionQuestion.class);
        util.exportExcel(response, list, "互动提问的问题数据");
    }

    /**
     * 获取互动提问的问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stdInteractionQuestionService.selectStdInteractionQuestionById(id));
    }

    /**
     * 新增互动提问的问题
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:add')")
    @Log(title = "互动提问的问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StdInteractionQuestion stdInteractionQuestion)
    {
        return toAjax(stdInteractionQuestionService.insertStdInteractionQuestion(stdInteractionQuestion));
    }

    /**
     * 修改互动提问的问题
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:edit')")
    @Log(title = "互动提问的问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StdInteractionQuestion stdInteractionQuestion)
    {
        return toAjax(stdInteractionQuestionService.updateStdInteractionQuestion(stdInteractionQuestion));
    }

    /**
     * 删除互动提问的问题
     */
    @PreAuthorize("@ss.hasPermi('study:interaction_question:remove')")
    @Log(title = "互动提问的问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stdInteractionQuestionService.deleteStdInteractionQuestionByIds(ids));
    }
}
